package com.wensi.utils

import android.content.Context
import android.content.SharedPreferences

/** SharePreference 工具类 */
object SpUtils {

    const val SP_NAME = "intelligent-config"

    // 对象
    private lateinit var sp: SharedPreferences
    private lateinit var spEditor: SharedPreferences.Editor

    fun initUtils(context: Context) {
        sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE)
        spEditor = sp.edit()
        spEditor.apply()

    }

    fun putString(key: String, value: String) {
        spEditor.putString(key, value)
    }
    fun getString(key: String): String? {
        return sp.getString(key, "")
    }

    fun putInt(key: String, value: Int) {
        spEditor.putInt(key, value)
    }
    fun getInt(key: String): Int? {
        return sp.getInt(key, -1)
    }

    fun putBoolean(key: String, value: Boolean) {
        spEditor.putBoolean(key, value)
    }
    fun getBoolean(key: String): Boolean? {
        return sp.getBoolean(key, false)
    }
}